﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="../../js/header.js"></script>
</head>
<body style="background-color: white;">
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <input type="hidden" id="pid" name="pid" value="0">
                <div class="tab-pane fade in active" id="home">
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>权限名称：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="pName" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>权限代码：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="pCode" maxlength="40" autocomplete="off" placeholder="长度必须介于 3 和 40 之间">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd100 control-label">状态：</label>
                        <div class="wd250 m15_l">
                            <label class="m10_r">
                                <input type="radio" name="hide" value="1"> 启用
                            </label>
                            <label>
                                <input type="radio" name="hide" value="2"> 禁用
                            </label>
                        </div>
                    </div>
                </div>
            </div>
        </form>

    </section>

    <script type="text/javascript">
        //角色状态
        var permissionStatus =
            {
                show: 1,
                hide: 2
            };

        var validator = null;

        $(function () {

            $("input[name=hide][value='2']").attr("checked", true);
            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Permission/GetAddOrEdit/",
                data: null,
                success: function (response) {
                },
                error: function (e) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试");
                }
            });
            validator = FlashPay.Util.Validator({
                formObj: $("#form"),
                rules: {
                    pName: {
                        required: true,
                        rangelength: [3,20]
                    },
                    pCode: {
                        required: true,
                        rangelength: [3, 20]
                    }
                },
                messages: {
                    pName: {
                        required: "长度必须介于 3 和 40 之间",
                        rangelength: "长度必须介于 3 和 40 之间",
                    },
                    pCode: {
                        required: "长度必须介于 3 和 40 之间",
                        rangelength: "长度必须介于 3 和 40 之间",
                    }
                },
            });

        })

        function save() {

            if (!validator.form()) {
                return false;
            }

            var permission = {};
            permission.pid = $("input[name='pid']").val();
            permission.pName = $("input[name='pName']").val();
            permission.pCode = $("input[name='pCode']").val();

            var hide = $(":radio[name='hide']:checked").val();
            if (hide == undefined) {
                FlashPay.UI.Tip_short_warning("请选择状态！");
                return;
            }
            permission.hide = hide;
            FlashPay.Util.Ajax({
                url: '/permission/SaveOrEdit',
                type: 'POST',
                data: { permission: permission },
                success: function (response) {
                    if (response.success) {
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                    }
                },
                error: function (json) {
                    FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试!");
                }
            });
        }
    </script>
</body>
</html>